﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;

namespace UI.ModSalary
{
    public partial class SalaryTrend : System.Web.UI.Page
    {
        SalaryTableBiz salaryTableBiz = new SalaryTableBiz();
        DefDicBiz defDicBiz = new DefDicBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               string strYear= System.DateTime.Now.Year.ToString();
                defDicBiz.InitXMLDropDownList(ddlYear, "YearList.xml", strYear); 
                 BondGrid(strYear);
            }
        }
        private void BindChart(int r, DataTable dt, string yValue, string xValue)
        {
            
            chMain.ChartAreas["ca"].AxisX.Interval = 1;
            //if (r <= 6)
            //{
            //    chMain.Height = r * 50;
            //    chMain.Width = r * 50;
            //    chMain.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
            //}
            //else
            //{
                chMain.Height = 280;
                chMain.Width = r * 90;
           // }
            chMain.IsSoftShadows = true;
            chMain.DataSource = dt;
            chMain.Series[0].YValueMembers = yValue;
            chMain.Series[0].XValueMember = xValue;
            chMain.DataBind();
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            string strYear = ddlYear.SelectedValue.Trim();
            BondGrid(strYear);
        }

        private void BondGrid(string strYear)
        {
            DataTable dt = salaryTableBiz.SalaryTrend(strYear, "1");
            int r = dt.Rows.Count;

                bTitle.Text = strYear + "年工资金额走势";
                BindChart(r, dt, "总额", "月份");
                gvList.DataSource = dt;
                gvList.DataBind();

        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strM = e.Row.Cells[0].Text.ToString();
                string strE= e.Row.Cells[1].Text.ToString();
                string strY = ddlYear.SelectedValue.Trim();

                string msg0 = "<a href=\"javascript:ShowLink('SalaryTrendMonth.aspx?StrMonth="+strM+"&StrYear=" + strY + "',880,550)\">"+strM+"</a>";
                string msg1 = "<a href=\"javascript:ShowLink('SalaryTrendMonth.aspx?StrMonth=" + strM + "&StrYear=" + strY + "',880,550)\">" + strE + "</a>";
                e.Row.Cells[0].Text = msg0;
                e.Row.Cells[1].Text = msg1;
            }
        }
    }
}